﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RM2012Server.Controller;
using DevComponents.DotNetBar.Controls;
using System.Data;

namespace RM2012Server.Model
{
    public static class GetID
    {
        #region Fields
        static AreaCtrl m_AreaCtrl = new AreaCtrl();
        #endregion

        public static String Area()
        {
            String lastId = m_AreaCtrl.GetLast();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "ARE" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "ARE" + "0" + num.ToString();
            }
            else
            {
                return "ARE" + num.ToString();
            }
        }

        public static String Area(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colAreaId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "ARE" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "ARE" + "0" + num.ToString();
            }
            else
            {
                return "ARE" + num.ToString();
            }
        }

        public static String Tables(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colTablesId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "TBL" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "TBL" + "0" + num.ToString();
            }
            else
            {
                return "TBL" + num.ToString();
            }
        }

        public static String States(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colStateId"].Value.ToString();
            int num = Convert.ToInt32(lastId) + 1;
            return num.ToString();
        }

        public static String UserGroup(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colUserGroupId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(1)) + 1;
            if (num < 10)
            {
                return "G" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "G" + "0" + num.ToString();
            }
            else
            {
                return "G" + num.ToString();
            }
        }

        public static String User(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colUserId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "USR" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "USR" + "0" + num.ToString();
            }
            else
            {
                return "USR" + num.ToString();
            }
        }

        public static String Unit(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colUnitId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "UNT" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "UNT" + "0" + num.ToString();
            }
            else
            {
                return "UNT" + num.ToString();
            }
        }

        public static String Cate(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colCateId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "CAT" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "CAT" + "0" + num.ToString();
            }
            else
            {
                return "CAT" + num.ToString();
            }
        }

        public static String Material(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colMaterialId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "MAT" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "MAT" + "0" + num.ToString();
            }
            else
            {
                return "MAT" + num.ToString();
            }
        }

        public static String Menu(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colMenuId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "MNU" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "MNU" + "0" + num.ToString();
            }
            else
            {
                return "MNU" + num.ToString();
            }
        }

        public static String Supplier(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colSupplierId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "SUP" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "SUP" + "0" + num.ToString();
            }
            else
            {
                return "SUP" + num.ToString();
            }
        }

        public static String Customer(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colCusId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "CUS" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "CUS" + "0" + num.ToString();
            }
            else
            {
                return "CUS" + num.ToString();
            }
        }

        public static String LastCustomerID()
        {
            DataTable dt = new CustomerCtrl().GetAll();
            String lastID = dt.Rows[dt.Rows.Count - 1]["CusId"].ToString();
            int iLast = Convert.ToInt32(lastID.Substring(3));
            iLast = iLast + 1;
            if (iLast < 10)
            {
                return "CUS" + "00" + iLast.ToString();
            }
            else if ((iLast >= 10) && (iLast < 100))
            {
                return "CUS" + "0" + iLast.ToString();
            }
            else
            {
                return "CUS" + iLast.ToString();
            }
        }

        public static String Booking(DataGridViewX dgv)
        {
            int count = dgv.Rows.Count;
            if (count > 0)
            {
                String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colBookId"].Value.ToString();
                int num = Convert.ToInt32(lastId.Substring(3)) + 1;
                if (num < 10)
                {
                    return "BOK" + "00" + num.ToString();
                }
                else if ((num >= 10) && (num < 100))
                {
                    return "BOK" + "0" + num.ToString();
                }
                else
                {
                    return "BOK" + num.ToString();
                }
            } 
            else
            {
                return "BOK001";
            }
        }

        public static String InventoryType(DataGridViewX dgv)
        {
            String lastId = dgv.Rows[dgv.Rows.Count - 1].Cells["colTypeId"].Value.ToString();
            int num = Convert.ToInt32(lastId.Substring(3)) + 1;
            if (num < 10)
            {
                return "IVT" + "00" + num.ToString();
            }
            else if ((num >= 10) && (num < 100))
            {
                return "IVT" + "0" + num.ToString();
            }
            else
            {
                return "IVT" + num.ToString();
            }
        }
    }
}
